<?php
/*
 *去哪儿商家添加标识，key，供应商产品id
*/
if(!$_SESSION['memberID']){
    exit('{"status":"fail","msg":"登录超时或未登陆"}');
}
include('../common/autoload.php');











// print_r($_REQUEST);
// exit;





// 清除配置
if($_REQUEST['ac']=='remove'){
    $sql="delete from uu_qunar_use where fid={$_SESSION['memberID']} and tid_aid='{$_POST['id']}' limit 1";
    if($GLOBALS['le']->query($sql)){
        exit('{"status":"ok","msg":"删除成功"}');
    }else{
        exit('{"status":"ok","msg":"其他错误，请联系管理员"}');
    }
    exit;
}
$supplierIdentity = $_REQUEST['Identity'];
$signkey = $_REQUEST['sign'];
$memberID = $_SESSION['sid'];
$cooperation_way = $_REQUEST['cooperation_way'];
// $DockingMode = $_REQUEST['DockingMode'];
$DockingMode = 0;

if(empty($supplierIdentity) && empty($signkey)){
	echo "<script>alert('供应商通信标识跟交互密钥不允许为空！');location.href='../qunaer.html';</script>";
	exit;
}
if(empty($_REQUEST['ids'])){
	echo "<script>alert('请选择已分销产品！');location.href='../qunaer.html';</script>";
}
$insTime = date('Y-m-d H:i:s');
$ins="INSERT INTO uu_qunar_use (tid_aid,supplierIdentity,signkey,fid,cooperation_way,itime,DockingMode) VALUES ";
$ins_f = false;
foreach($_REQUEST['ids'] as $k=>$id){
    $select_ids = "select * from uu_qunar_use where tid_aid = '$id' limit 1"; 
	$GLOBALS['le']->query($select_ids);
	if($GLOBALS['le']->fetch_assoc()){
		echo "<script>alert('此产品已存在，请重新选择！');location.href='../qunaer.html';</script>";	break;		
	}
    $id = htmlspecialchars($id);
	$ins_f = true;
	$ins.="('$id','$supplierIdentity','$signkey',$memberID,'$cooperation_way','$insTime',$DockingMode),";
}
if($ins_f){
	$ins = substr($ins,0,-1);
	if($GLOBALS['le']->query($ins)){
		echo "<script>alert('添加成功');location.href='../qunaer.html';</script>"; 
	}
	else{
		echo "<script>alert('添加失败');location.href='../qunaer.html';</script>";
	}
}

?>